package com.sgb.kjwl.view.ui.adapter.self.carMasters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.CarMasterOderEntity;
import com.sgb.kjwl.model.entity.self.CarriageManageEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class TransportationOrderManagementAdapter extends BaseRecycleAdapter<CarMasterOderEntity> {

    private ImageView state_img;
    private TextView tv_run;
    private TextView tv_cancel;
    private TextView tv_delete;
    private TextView tv_arrive;
    private TextView tv_goods_details;
    private IButtonClick iButtonClick;

    public TransportationOrderManagementAdapter(Context context, List<CarMasterOderEntity> datas) {
        super(context, R.layout.item_transportation_order_management, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final CarMasterOderEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvTime=holder.getItem().findViewById(R.id.tv_time);
        state_img = holder.getItem().findViewById(R.id.state_img);
        tv_run = holder.getItem().findViewById(R.id.tv_run);
        tv_cancel = holder.getItem().findViewById(R.id.tv_cancel);
        tv_delete = holder.getItem().findViewById(R.id.tv_delete);
        tv_arrive = holder.getItem().findViewById(R.id.tv_arrive);
        tv_goods_details = holder.getItem().findViewById(R.id.tv_goods_details);
        TextView tvFreight=holder.getItem().findViewById(R.id.tv_freight);
        tvFreight.setText(entity.getFreight()+"元/吨");
        tvTime.setText(DateUtils.stampToDay2(entity.getShipmentTime())+"~"+DateUtils.stampToDay2(entity.getShipmentEndTime()));
        tv_goods_details.setText(entity.getGoodsModelName()+"/"+entity.getWeight());
// 订单状态 0 待确认 1 待发车 2 运输中 3已完成 4 已取消
        switch (entity.getStatus()) {
            case "0":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_dqr));
                tv_run.setVisibility(View.GONE);
                tv_cancel.setVisibility(View.VISIBLE);
                tv_arrive.setVisibility(View.GONE);
                tv_delete.setVisibility(View.GONE);
                break;
            case "1":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_dfc));
                tv_run.setVisibility(View.VISIBLE);
                tv_cancel.setVisibility(View.VISIBLE);
                tv_arrive.setVisibility(View.GONE);
                tv_delete.setVisibility(View.GONE);
                break;
            case "2":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_ysz));
                tv_run.setVisibility(View.GONE);
                tv_cancel.setVisibility(View.GONE);
                tv_arrive.setVisibility(View.VISIBLE);
                tv_delete.setVisibility(View.GONE);
                break;
            case "3":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_ywc));
                tv_run.setVisibility(View.GONE);
                tv_cancel.setVisibility(View.GONE);
                tv_arrive.setVisibility(View.GONE);
                tv_delete.setVisibility(View.GONE);
                break;
            case "4":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_yqx));
                tv_run.setVisibility(View.GONE);
                tv_cancel.setVisibility(View.GONE);
                tv_delete.setVisibility(View.VISIBLE);
                break;
        }
        tv_run.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iButtonClick.fuckCar(entity.getOrderNo());
            }
        });
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iButtonClick.onCancel(entity.getOrderNo());
            }
        });
        tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iButtonClick.onDelete(entity.getOrderNo());
            }
        });

        tv_arrive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iButtonClick.onArrive(entity.getOrderNo());
            }
        });

    }

    public interface IButtonClick {
        void fuckCar(String orderNo);

        void onCancel(String orderNo);

        void onDelete(String orderNo);

        void onArrive(String orderNo);
    }

    public void onButtonClick(IButtonClick iButtonClick) {
        this.iButtonClick = iButtonClick;
    }
}
